package at.fhv.components.opening;

import javax.media.jai.KernelJAI;

import at.fhv.components.dilate.DilateFilter;
import at.fhv.components.erode.ErodeFilter;
import at.fhv.framework.events.ImageEvent;
import at.fhv.framework.listeners.ImageProcessingListener;
import at.fhv.framework.listeners.RefireListener;

/**
 * The ImagePanel class.
 * 
 * @author Michael Sieber
 */
public class OpeningFilter implements ImageProcessingListener, RefireListener 
{
	private ErodeFilter _erode;
	private DilateFilter _dilate;
	private KernelJAI _erodeKernel;
	private KernelJAI _dilateKernel;

	/**
	 * Create a new ImagePanel
	 */
	public OpeningFilter() {
		_erode = new ErodeFilter();
		_dilate = new DilateFilter();

		_erodeKernel = _erode.getKernel();
		_dilateKernel = _dilate.getKernel();

		_erode.addImageChangeListener(_dilate);
	}

	/**
	 * @return The erodeKernel
	 */
	public KernelJAI getErodeKernel() {
		return _erodeKernel;
	}

	/**
	 * @param erodeKernel The erodeKernel to set
	 */
	public void setErodeKernel(KernelJAI erodeKernel) {
		_erodeKernel = erodeKernel;
		_erode.setKernel(_erodeKernel);
	}

	/**
	 * @return The dilateKernel
	 */
	public KernelJAI getDilateKernel() {
		return _dilateKernel;
	}

	/**
	 * @param dilateKernel The dilateKernel to set
	 */
	public void setDilateKernel(KernelJAI dilateKernel) {
		_dilateKernel = dilateKernel;
		_dilate.setKernel(_dilateKernel);
	}

	/*
	 * {@inheritDoc}
	 */
	@Override
	public void imageChanged(ImageEvent event) {
		_erode.imageChanged(event);
	}

	/*
	 * {@inheritDoc}
	 */
	@Override
	public void addRefireListener(RefireListener listener) {
		_erode.addRefireListener(listener);
	}

	/*
	 * {@inheritDoc}
	 */
	@Override
	public void removeRefireListener(RefireListener listener) {
		_erode.removeRefireListener(listener);
	}

	/*
	 * {@inheritDoc}
	 */
	@Override
	public void refire() {
		_erode.refire();
	}

	/**
	 * Add an image change listener
	 * 
	 * @param listener The image change listener to add
	 */
	public void addImageChangeListener(ImageProcessingListener listener) {
		_dilate.addImageChangeListener(listener);
	}

	/**
	 * Remove an image change listener
	 * 
	 * @param listener The image change listener to remove
	 */
	public void removeImageChangeListener(ImageProcessingListener listener) {
		_dilate.removeImageChangeListener(listener);
	}

}
